function Set-NonVolatileLinks {
<#
.SYNOPSIS
Creates symbolic links in the current directory to the provided path

.PARAMETER NonVolatileDir
The path containing the ddirectories to be linked. The default is the directory containing the NonVolatile workspace.

.LINK
https://BigGit.Codeplex.com
Add-NonVolatileEnlistment
#>
    param(  [string] $nonVolatileDir = $null )
    if(!$nonVolatileDir) { $nonVolatileDir = Get-BigGitConfig "NonVolatilePath" }
    if(!$nonVolatileDir) {
        Write-BigGitMessage "No Nonvolatile workspace found to link from. No symbolic links created"
        return
    }
    $nonVolatileDir=Resolve-Path $nonVolatileDir
    Set-Link (Resolve-Path .) $nonVolatileDir
}

function Set-Link($currentFolder, $nonVolatileDir, $searchFolder=""){
    write-debug "setting with $currentFolder $nonVolatileDir $searchFolder"
    Get-ChildItem "$nonVolatileDir\$searchFolder" | % {
        #Delete empty folder in volatile space
        if((Test-TruePath "$currentFolder\$searchFolder\$_") -and !(Get-ChildItem "$currentFolder\$searchFolder\$_")){
            write-debug "Removing $currentFolder\$searchFolder\$_"
            remove-item "$currentFolder\$searchFolder\$_"
        }
        #no matching volatile folder - LINK to it
        if(!(test-Path "$currentFolder\$searchFolder\$_")){
            write-debug "creating link for $currentFolder\$searchFolder\$_ TO $nonVolatileDir\$searchFolder\$_"
            if((test-Path "$nonVolatileDir\$searchFolder\$_" -PathType Container)){
                #Directory Link
                Cmd /c mklink /d "$currentFolder\$searchFolder\$_" "$nonVolatileDir\$searchFolder\$_"
            }
            else {
                #FileLink
                Cmd /c mklink "$currentFolder\$searchFolder\$_" "$nonVolatileDir\$searchFolder\$_"
            }
        }
        # volatile has a matching folder, traverse child folders
        elseif((Test-TruePath "$currentFolder\$searchFolder\$_")){
            Set-Link $currentFolder $nonVolatileDir "$searchFolder\$_"
        }
    }
}

#Does the directory exist and not as a link
function Test-TruePath($path){
    if((Test-Path $path -PathType Container)){
        $item = Get-Item $path
        if(!([bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint))){
            return $true
        }
    }
    return $false
}